package com.qimei.onerice.service.impl;

import com.qimei.onerice.dao.DishCategoryDao;
import com.qimei.onerice.dao.DishDao;
import com.qimei.onerice.dao.impl.DishCategoryDaoImpl;
import com.qimei.onerice.dao.impl.DishDaoImpl;
import com.qimei.onerice.entity.Dish;
import com.qimei.onerice.entity.DishCategory;
import com.qimei.onerice.service.DishCategoryService;
import com.qimei.onerice.service.DishService;

import java.util.List;

public class DishServiceImpl implements DishService {
	DishDao dishDao = new DishDaoImpl();
	DishCategoryService dishCategoryService = new DishCategoryServiceImpl();

	@Override
	public List<Dish> getDishList() {
		return dishDao.getAllDishes();
	}

	@Override
	public boolean deleteDish(int dishId) {
		int result = dishDao.deleteDish(dishId);
		return result > 0;
	}

	@Override
	public boolean updateDish(Dish dish) {
		int result = dishDao.updateDish(dish);
		return result > 0;
	}

	@Override
	public boolean addDish(Dish dish) {
		int result = dishDao.addDish(dish);
		return result > 0;
	}

	@Override
	public List<Dish> getDishListByNameLike(String dishName) {
		return null;
	}

	@Override
	public List<Dish> getDishListByCategoryId(int categoryId) {
		return dishDao.getDishListByCategoryId(categoryId);
	}

	@Override
	public Dish getDishById(int dishId) {
		Dish dishById = dishDao.getDishById(dishId);
		DishCategory dishCategoryById = dishCategoryService.getDishCategoryById(dishById.getCategoryId());
		if (dishCategoryById != null) {
			dishById.setCategoryName(dishCategoryById.getCategoryName());
		}
		return dishById;
	}
}
